package manager.xml {
	import com.debug.TDebug;
	
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	public class XMLConfig extends XMLBaseManage {
		public var wsdl:String;
		public var socket:String;
		public var port:uint;
		public var key:String;
		
		private static var _instance:XMLConfig;
		
		public function XMLConfig() {
			if(_instance!=null){
				throw Error("请用单例");
			}
		}
		
		/**
		 * 解析传入的XML 
		 */		
		override public function set setXML(val:XML):void {
			super.setXML = val;
			socket = this._xml.children()[0].@socket;
			port   = this._xml.children()[0].@port;
			key    = this._xml.children()[0].@key;
			wsdl   = this._xml.children()[0].@web;
		}
		/**
		 * 单个xml路径解析
		 * 另：可通过blur加载xml
		 * @param _url
		 * @param callBack
		 */		
		public function sendXML(_url:String,callBack:Function):void{
			var request:URLRequest = new URLRequest("xml/Config.xml");
			var loader:URLLoader = new URLLoader();
			loader.addEventListener(Event.COMPLETE,callBack);
			loader.addEventListener(IOErrorEvent.IO_ERROR,function(e:IOErrorEvent):void{
				TDebug.trace("IO出错：" + _url);
			});
			loader.load(request);
		}
		
		public static function getInstance():XMLConfig{
			if(_instance==null){
				_instance = new XMLConfig();
			}
			return _instance;
		}
		
		override public function dispose():void {
			super.dispose();
			_instance = null;
		}
	}
}